﻿@using LanDBom.Models
@using LanDBom.Resources
@{
    ViewBag.Title = "Overview";
}
<div>
    <from>
        <fieldset class="boun">
            <legend></legend>
            <div class="row bian">
                <label class="col-sm-3 breadcrumb-item">步骤四：采购询价</label>
                <ul id="lisul" class="row col-sm-5">
                    <li class="lisu"></li>&rArr;
                    <li class="lisu"></li>&rArr;
                    <li class="lisu"></li>&rArr;
                    <li class="lisu">4</li>&rArr;
                    <li class="lisu"></li>&rArr;
                    <li class="lisu"></li>&rArr;
                    <li class="lisu"></li>
                </ul>
            </div>
        </fieldset>
    </from>
</div>
<div>
    <from class="from-horizontal">
        <div>
            <fieldset class="boun nav" style="padding-bottom:6px;">
                <legend class="len">@Resource.String155</legend>
                <div class="col-lg-3">@Resource.String163:<input type="text" style="width:150px;" id="txtbian" /></div>
                <div class="col-lg-3">@Resource.String164:<input type="text" style="width: 150px;" id="txtKH" /></div>
                <div class="col-lg-3">@Resource.String165:<input type="text" style="width: 150px;" id="txtqishi" /></div>
                <div calss="col-lg-3"><button id="findApp" class="btn-sm  btn-secondary">@Resource.String155</button>&nbsp;&nbsp;<button id="reste" class="btn-sm btn-secondary">返回</button></div>
            </fieldset>
            <div style="display: none; position: fixed; background-color:dimgray;border:1px double black;overflow:scroll;max-height:70%" id="black_BOX" class="row">
                <div id="black_BOX_TC" class="col-2" style="color:white">@Resource.String166</div>
                <div class="col-1"></div>
                <div id="black_BOX_YJTJ" class="col-2" style="color:white">@Resource.String167</div>
                <div>
                    <table class="table table-sm gun" style="background-color: #FFFFFF">
                        <thead class="thead-light">
                            <tr>
                                <th scope="col" style="width:20px"><input type="checkbox" id="HJ_All_cb" /></th>
                                <th scope="col">@Resource.String168</th>
                                <th scope="col">@Resource.String169</th>
                                <th scope="col">@Resource.String170</th>
                                <th scope="col">@Resource.String171</th>
                                <th scope="col">@Resource.String172</th>
                                <th scope="col">@Resource.String173</th>
                                <th scope="col">@Resource.String174</th>
                                <th scope="col">@Resource.String175</th>
                                <th scope="col">@Resource.String176</th>
                                <th scope="col">@Resource.String177</th>
                                <th scope="col">@Resource.String178</th>
                            </tr>
                        </thead>
                        <tbody data-spy="scroll" id="CG_Inf_Tbody">
                        </tbody>
                    </table>
                </div>

            </div>
        </div>
        <div class="tab">
            <fieldset class="boun nav">
                <legend class="len">申请单</legend>
                <table class="table table-sm gun">
                    <thead class="thead-light">
                        <tr class="GEN-cent">
                            <th scope="col" style="width:60px">@Resource.String156</th>
                            <th scope="col">@Resource.String179</th>
                            <th scope="col"  style="width:370px;">@Resource.String180</th>
                            <th scope="col">@Resource.String181</th>
                            <th scope="col">@Resource.String182</th>
                            <th scope="col">@Resource.String183</th>
                            <th scope="col">@Resource.String184</th>
                        </tr>
                    </thead>
                    <tbody  id="AppTable" style="height:500px;">
                        
                    </tbody>
                </table>
            </fieldset>
        </div>
    </from>
</div>



@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>

        $(function () {
            $("#li5").css({ "color": "black", "background-color": "white" })
            //加载询价信息
            //$(document).on("click", "#CG_CK", function (e) {
            //    var SQ_CG = $(e.target).parent().children().first().next().text()
            //    $("#black_BOX").css({ "display": "block" })
            //    $.ajax({
            //        url: '/Procure/Overview',
            //        type: 'GET',
            //        data: { "App_bian": SQ_CG, "state": 2 },
            //        success: function (data) {
            //            createTR(data);
            //        },
            //        error: function () {
            //            alert('Request Error');
            //        }
            //    })
            //})
            //打印询价信息表格
            function createTR(data) {
                $('#CG_Inf_Tbody tr').remove();
                $.each(data, function (i, item) {
                    var $tr = $(`
                                    <tr>
                                        <td style="width:20px"> <input type="checkbox" name="HJ_TJK" value="x"/></td>
                                        <td id="Inf_id">${item.Inf_id}</td>
                                        <td>${item.Inf_shen}</td>
                                        <td>${item.Inf_wu}</td>
                                        <td>${item.Inf_liao}</td>
                                        <td>${item.Inf_miao}</td>
                                        <td>${item.Inf_nian}</td>
                                        <td>${item.Inf_gong}</td>
                                        <td>${item.Inf_huiTime}</td>
                                        <td><input style="width:50px" name="GYSJG" value="${item.Inf_huiP}" type="number"/></td>
                                        <td id="inf_zHUaNg">${item.Inf_zhuang}</td>
                                        <td id="CG_HJ">@Resource.String186</td>
                                        <td id="CG_SH">@Resource.String187</td>
                                    </tr>

                                `);
                    $('#CG_Inf_Tbody').append($tr);
                })
            }
            //批量提交供应商回价
            $(document).on("click", "#black_BOX_YJTJ", function () {
                var HJ_jg = []
                var hang = $("input[name='HJ_TJK']:checked").parent().length
                console.log(hang)
                var Tiaojan = 0;
                $("input[name='HJ_TJK']:checked").parent().parent().each(function (i, KOO) {
                    var sjjd = $("input[name='HJ_TJK']:checked", KOO).parent().parent().children().eq(10).text()
                    if (sjjd=="审批中") {
                        Tiaojan++;
                    }
                })
                if (hang <= 0) {
                    alert("请选择要恢复的价格")
                } else if (Tiaojan>0) {
                    alert("该条在审批，请等待");
                }
                else {
                    $("input[name='HJ_TJK']:checked").parent().parent().each(function (i, item) {
                        if ($("td[id=inf_zHUaNg]", item).text != "已提交") {
                            HJ_jg.push({
                                Inf_id: $("td[id='Inf_id']", item).text(),
                                Inf_zhuang: "已提交",
                                Inf_huiP: $("input[name='GYSJG']", item).val()
                            })
                        }
                    })
                    console.log("共" + HJ_jg.length + "数据");
                    console.log(HJ_jg);
                    $.ajax({
                        url: "/Procure/Modify_All_GYS_HJ",
                        type: "POST",
                        data: JSON.stringify(HJ_jg),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (text) {
                            if (text > 0) {
                                alert("添加成功" + text.msg);

                            } else {
                                alert("添加失败" + text.msg);
                            }

                        },
                        error: function (text) {
                            alert("系统错误" + text);
                        }
                    })
                }
            })
            //添加步骤自增
            //$(document).on('click', '#CG_SH', function (e) {
            //    var CG_INFSQD = $(e.target).prev().prev().prev().prev().prev().prev().prev().prev().prev().prev().text()
            //    $.ajax({
            //        url: '/Procure/Index',
            //        type: 'POST',
            //        data: { "CG_INFSQD": CG_INFSQD },
            //        success: function (data) {
            //        },
            //        error: function () {
            //            alert('Request Error');
            //        }
            //    })
            //})
            //转跳到核价页面
            $(document).on('click', '#CG_SH', function (e) {
                var shinfd = $(e.target).prev().prev().text()
                console.log(shinfd)
                if (shinfd == "已提交") {
                    var CG_INFSQD = $(e.target).prev().prev().prev().prev().prev().prev().prev().prev().prev().prev().text()
                    window.location.href = "/Procure/pricing_New?APP_bian=" + CG_INFSQD;
                } else {
                    alert("请刷新查看单据状态")
                }

            })

            //打开回价隐藏页面
            //$("#black_BOX_TC").click(function () {
            //    $("#black_BOX").css({ "display": "none" })
            //    $("#CG_Inf_Tbody tr").remove()
            //})
            //提交供应商回价信息
            $(document).on('click', '#CG_HJ', function (e) {
                var CG_GYSHJ = $(e.target).prev().prev().children().val()
                var CG_HJZT = $(e.target).prev().text();
                //alert(CG_GYSHJ)
                var CG_INFID = $(e.target).prev().prev().prev().prev().prev().prev().prev().prev().prev().prev().text()
                //alert(CG_INFID)
                if (CG_GYSHJ == "") {
                    alert("请输入供应商的回价")
                }
                else {
                    if (CG_HJZT == "审批中") {
                        alert("正在审批请等待")
                    } else if (CG_HJZT != "等待中") {
                        alert("已提交或已过期请勿提交")
                    } else{
                        var gys_wl_jg = {
                            Inf_id: CG_INFID,
                            Inf_zhuang: "已提交",
                            Inf_huip: CG_GYSHJ
                        }
                        $.ajax({
                            url: "/Procure/Modify_GYS_HJ",
                            type: "POST",
                            data: gys_wl_jg,
                            success: function (data) {
                                if (data == "修改成功")
                                    alert(data);
                            },
                            error: function (data) {
                                alert("erroer ");
                            },
                        })
                    }
                }
            })
             /*if (CG_HJZT == "审批中") {
                        alert("正在审核请等待");
                    }
                    else*/
            //全选
            $(document).on("click", "#HJ_All_cb", function (e) {
                if ($(e.target).prop("checked")) {
                    $("input[name='HJ_TJK']").each(function (i, item) {
                        var x = $(item).parent().parent().children().eq(9).children().val()
                        if (x != "") {
                            $(item).prop("checked", true);
                        }
                    })
                }
                else {
                    $("input[name='HJ_TJK']").prop("checked", false);

                }
            })

            find_sqd()
            //搜索询价申请单的方法
            function find_sqd() {
                var txtbian = $("#txtbian").val();
                var txtKH = $("#txtKH").val();
                var txtqishi = $("#txtqishi").val();
                $.ajax({
                    url: '/Procure/Overview',
                    type: 'GET',
                    data: { "App_bian": txtbian, "App_KHname": txtKH, "App_xiang": txtqishi, "state": 1 },
                    success: function (data) {
                        console.log(data)
                        createRow(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }

            function createRow(data2) {
                $('#AppTable tr').remove();
                var indsjkdjk = 1
                $.each(data2, function (i, item) {
                    var bians = item.AP_bian
                    var index = ""
                    $.ajax({
                        url: '/Procure/Overview',
                        type: 'GET',
                        data: { "App_bian": item.AP_bian,"state": 6 },
                        success: function (data) {
                            console.log(data)
                            if (data == "添加") {
                                $.ajax({
                                    url: '/Procure/Overview',
                                    type: 'POST',
                                    data: { "App_bian": item.AP_bian, "state": 3 },
                                    success: function (data) {
                                        console.log(data)
                                        if ($("#Login_sf").text() == "采购主管" || $("#Login_sf").text() == "业务发展部经理") {
                                            var $tr =
                                                $(`
                                                    <tr>
                                                        <td style="width:60px">${indsjkdjk}</td>
                                                        <td><a id="CG_ZT" href="#">${item.AP_bian}</a></td>
                                                        <td style="width:370px">${item.App_Kehu}</td>
                                                        <td>${item.App_qishi}</td>
                                                        <td>${item.App_JTime}</td>
                                                        <td>${item.APP_name}</td>
                                                        <td>${data}</td>
                                                    </tr>

                                                `);
                                            $('#AppTable').append($tr);
                                            indsjkdjk++
                                        }
                                        else if ($("#Login_sf").text() == "采购员") {
                                            $.ajax({
                                                url: '/Procure/Price_main',
                                                type: 'GET',
                                                data: { "App_bian": bians, "state": 12, "id": $("#Login_name").text() },
                                                success: function (date) {
                                                    console.log(date)
                                                    var $tr =
                                                        $(`
                                                                 <tr style="height:50px">
                                                                     <td style="width:60px">${indsjkdjk}</td>
                                                                     <td><a id="CG_ZT"  href="#">${item.AP_bian}</a></td>
                                                                     <td style="width:370px">${item.App_Kehu}</td>
                                                                     <td>${item.App_qishi}</td>
                                                                     <td>${item.App_JTime}</td>
                                                                     <td>${item.APP_name}</td>
                                                                     <td>${data}</td>
                                                                 </tr>
                                                        `);
                                                    if (date == "添加") {
                                                        $('#AppTable').append($tr);
                                                        indsjkdjk++
                                                    }

                                                },
                                                error: function () {
                                                    alert('Request Error');
                                                }
                                            })
                                        }
                                    },
                                    error: function (data) {
                                    }
                                })
                            }
                        },
                        error: function () {
                            alert('Request Error');
                        }
                    })
                })
                var len = $('#AppTable tr').length;
                for (var i = 0; i < len; i++) {
                    $('#AppTable tr:eq(' + i + ') td:first').text(i + 1);
                }
            }
            //打印申请表信息
            $("#findApp").click(function () {
                find_sqd()
            })
        })

        $(function () {


            //点击转跳到询价页面
            $(document).on("click", "#CG_ZT", function (e) {
                if ($("#Login_bm").text() == "采购"||$("#Login_sf").text()=="业务发展部经理") {
                    var APP_Bian = $(e.target).text()
                    location.href = "/Procure/Detailed?APP_bian=" + APP_Bian;
                }
                else {
                    alert("权限不足")
                }
                    
            })

            //废弃代码

            //$("a").click(function (e) {
            //    alert(123)
            //    var APP_Bian = $(e.target).text()
            //    $.ajax({
            //        url: '/Procure/Overview',
            //        type: 'GET',
            //        data: { "CG_INFSQD": APP_Bian },
            //        success: function (data) {
            //            $(location).attr('href', '/Procure/Detailed')
            //        },
            //        error: function () {
            //            alert('Request Error');
            //        }
            //    })
            //})

        })
    </script>
}